package com.fw.ui.util;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.context.annotation.Scope;

import com.fw.ui.view.AbstractView;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.PopupDateField;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;

@org.springframework.stereotype.Component
@Scope(SCOPE_PROTOTYPE)
public class UICommonUtils {

    @SuppressWarnings("rawtypes")
    public static final Map<Class, String> MAP_ERROR_STYLES = new HashMap<Class, String>();

    static {
	MAP_ERROR_STYLES.put(TextField.class, "v-textfield-error");
	MAP_ERROR_STYLES.put(TextArea.class, "v-textarea-error");
	MAP_ERROR_STYLES.put(PopupDateField.class, "v-datefield-error");
	MAP_ERROR_STYLES.put(DateField.class, "v-datefield-error");
	MAP_ERROR_STYLES.put(ComboBox.class, "v-filterselect-error");
	MAP_ERROR_STYLES.put(PasswordField.class, "v-textfield-error");
    }

    public static final String EXCLUDE_ENABLE_COMPONENT_PREFIX = "_EX_ENABLE";
    public static final String INCLUDE_ENABLE_COMPONENT_PREFIX = "_IN_ENABLE";

    public static final String EXCLUDE_VALUE_COMPONENT_PREFIX = "_EX_VALUE";
    public static final String INCLUDE_VALUE_COMPONENT_PREFIX = "_IN_VALUE";

    public static final String EXCLUDE_STYLE_COMPONENT_PREFIX = "_EX_STYLE";
    public static final String INCLUDE_STYLE_COMPONENT_PREFIX = "_IN_STYLE";

    public static final String EXCLUDE_VISIBLE_COMPONENT_PREFIX = "_EX_VISIBLE";
    public static final String INCLUDE_VISIBLE_COMPONENT_PREFIX = "_IN_VISIBLE";

    public void setEnableUIComponents(List<Component> components, List<Component> excludeComponent, boolean enabled) {
	if (components != null) {
	    for (Component component : components) {
		if (component == null) {
		    continue;
		}
		if (excludeComponent != null && !excludeComponent.isEmpty() && excludeComponent.contains(component)) {
		    continue;
		}
		Object obj = component.getId();
		if (obj != null && obj instanceof String) {
		    String dataStr = (String) obj;
		    if (dataStr.indexOf(EXCLUDE_ENABLE_COMPONENT_PREFIX) > 0) {
			continue;
		    }
		}
		setEnableUIComponent(component, enabled);
	    }
	}
    }

    public void setEnableUIComponent(Component component, boolean enabled) {
	if (component != null) {
	    component.setEnabled(enabled);
	}
    }

    public void setEnableAllUIComponent(Component component, List<Component> excludeComponent, boolean enabled) {
	if (component != null) {
	    if (excludeComponent != null && !excludeComponent.isEmpty() && excludeComponent.contains(component)) {
		return;
	    }
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_ENABLE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		view.setEnabled(true);
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			setEnableAllUIComponent(componentIns, excludeComponent, enabled);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		layout.setEnabled(true);
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			setEnableAllUIComponent(component2, excludeComponent, enabled);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		panel.setEnabled(true);
		setEnableAllUIComponent(panel.getContent(), excludeComponent, enabled);
	    } else {
		component.setEnabled(enabled);
	    }
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(INCLUDE_ENABLE_COMPONENT_PREFIX) > 0) {
		    component.setEnabled(enabled);
		}
	    }
	}
    }

    public void setEnableAllUIComponent(Component component, boolean enabled) {
	if (component != null) {
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_ENABLE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			setEnableAllUIComponent(componentIns, enabled);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			setEnableAllUIComponent(component2, enabled);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		setEnableAllUIComponent(panel.getContent(), enabled);
	    } else {
		component.setEnabled(enabled);
	    }
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(INCLUDE_ENABLE_COMPONENT_PREFIX) > 0) {
		    component.setEnabled(enabled);
		}
	    }
	}
    }

    public void clearValueAllUIComponent(Component component, List<Component> excludeComponent) {
	if (component != null) {
	    if (excludeComponent != null && !excludeComponent.isEmpty() && excludeComponent.contains(component)) {
		return;
	    }
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		view.setVisible(true);
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			clearValueAllUIComponent(componentIns, excludeComponent);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		layout.setVisible(true);
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			clearValueAllUIComponent(component2, excludeComponent);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		panel.setVisible(true);
		clearValueAllUIComponent(panel.getContent(), excludeComponent);
	    } else {
		setValueUIComponent(component, null);
	    }
	}
    }

    public void clearValueAllUIComponentExcludeLabelWithDefaultValue(Component component, Map<Component, Object> mapDefaultValue) {
	if (component != null) {
	    if (mapDefaultValue == null) {
		mapDefaultValue = new HashMap<Component, Object>();
	    }
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		view.setVisible(true);
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			clearValueAllUIComponentExcludeLabelWithDefaultValue(componentIns, mapDefaultValue);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		layout.setVisible(true);
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			clearValueAllUIComponentExcludeLabelWithDefaultValue(component2, mapDefaultValue);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		panel.setVisible(true);
		clearValueAllUIComponentExcludeLabelWithDefaultValue(panel.getContent(), mapDefaultValue);
	    } else if (!(component instanceof Label)) {
		Object defaultValue = mapDefaultValue.get(component);
		setValueUIComponent(component, defaultValue);
	    } else if (component instanceof Label) {
		if (obj != null && obj instanceof String) {
		    Object defaultValue = mapDefaultValue.get(component);
		    String dataStr = (String) obj;
		    if (dataStr.indexOf(INCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
			setValueUIComponent(component, defaultValue);
		    }
		}
	    }
	}
    }

    public void clearValueAllUIComponentExcludeLabel(Component component) {
	if (component != null) {
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		view.setVisible(true);
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			clearValueAllUIComponentExcludeLabel(componentIns);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		layout.setVisible(true);
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			clearValueAllUIComponentExcludeLabel(component2);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		panel.setVisible(true);
		clearValueAllUIComponentExcludeLabel(panel.getContent());
	    } else if (!(component instanceof Label)) {
		setValueUIComponent(component, null);
	    } else if (component instanceof Label) {
		if (obj != null && obj instanceof String) {
		    String dataStr = (String) obj;
		    if (dataStr.indexOf(INCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
			setValueUIComponent(component, null);
		    }
		}
	    }
	}
    }

    public void clearValueAllUIComponent(Component component) {
	if (component != null) {
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		view.setVisible(true);
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			clearValueAllUIComponent(componentIns);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		layout.setVisible(true);
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			clearValueAllUIComponent(component2);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		panel.setVisible(true);
		clearValueAllUIComponent(panel.getContent());
	    } else {
		setValueUIComponent(component, null);
	    }
	}
    }

    public void setValueUIComponents(Map<Component, Object> components) {
	if (components != null) {
	    for (Entry<Component, Object> component : components.entrySet()) {
		if (component == null || component.getKey() == null) {
		    continue;
		}
		Object obj = component.getKey().getId();
		if (obj != null && obj instanceof String) {
		    String dataStr = (String) obj;
		    if (dataStr.indexOf(EXCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
			return;
		    }
		}
		setValueUIComponent(component.getKey(), component.getValue());
	    }
	}
    }

    public void setValueUIComponent(Component component, Object defaultValue) {
	if (component != null) {
	    boolean isreadOnly = component.isReadOnly();
	    component.setReadOnly(false);
	    if (component instanceof TextField) {
		TextField textfield = (TextField) component;
		textfield.setValue((defaultValue == null ? "" : defaultValue.toString()));
	    } else if (component instanceof Label) {
		Label label = (Label) component;
		label.setValue((defaultValue == null ? "" : defaultValue.toString()));
	    } else if (component instanceof PasswordField) {
		PasswordField passwordField = (PasswordField) component;
		passwordField.setValue((defaultValue == null ? "" : defaultValue.toString()));
	    } else if (component instanceof DateField) {
		DateField datefield = (DateField) component;
		// if (defaultValue != null) {
		// if (defaultValue instanceof String && defaultValue != null && !defaultValue.toString().isEmpty()) {
		// String pattern = datefield.getDateFormat();
		// System.out.println("pattern ="+pattern);
		// Date date = null;
		// if (StringUtils.PATTERN_MONTH_YEAR_UI.equals(pattern)) {
		// date = StringUtils.parseDate(defaultValue.toString(), StringUtils.PATTERN_MONTH_YEAR_PERSISTENCE);
		// } else if (StringUtils.PATTERN_DATE_UI.equals(pattern)) {
		// date = StringUtils.parseDate(defaultValue.toString(), StringUtils.PATTERN_DATE_PERSISTENCE);
		// } else if (StringUtils.PATTERN_DATETIME_UI.equals(pattern)) {
		// date = StringUtils.parseDate(defaultValue.toString(), StringUtils.PATTERN_DATETIME_PERSISTENCE);
		// }
		// datefield.setValue(date);
		// } else {
		// datefield.setValue((Date) defaultValue);
		// }
		// } else {
		// datefield.setValue(null);
		// }
		if (defaultValue instanceof Date) {
		    datefield.setValue((Date) defaultValue);
		} else {
		    datefield.setValue(null);
		}
	    } else if (component instanceof TextArea) {
		TextArea textArea = (TextArea) component;
		textArea.setValue((defaultValue == null ? "" : defaultValue.toString()));
	    } else if (component instanceof ComboBox) {
		ComboBox comboBox = (ComboBox) component;
		comboBox.setValue(defaultValue);
		comboBox.select(defaultValue);
	    } else if (component instanceof CheckBox) {
		CheckBox checkBox = (CheckBox) component;
		checkBox.setValue((defaultValue == null ? false : (boolean) defaultValue));
	    } else if (component instanceof OptionGroup) {
		OptionGroup optionGroup = (OptionGroup) component;
		optionGroup.setValue(defaultValue);
		optionGroup.select(defaultValue);
	    }
	    component.setReadOnly(isreadOnly);
	}
    }

    public void addStyleUIComponents(Map<Component, String> components) {
	if (components != null) {
	    for (Entry<Component, String> component : components.entrySet()) {
		if (component == null || component.getKey() == null || component.getValue() == null) {
		    continue;
		}
		Component componentIns = component.getKey();
		String styleName = component.getValue();
		addStyleUIComponent(componentIns, styleName);
	    }
	}
    }

    public void addStyleUIComponent(Component component, String styleName) {
	if (component != null && styleName != null) {
	    component.addStyleName(styleName);
	}
    }

    public void removeStyleUIComponents(Map<Component, String> components) {
	if (components != null) {
	    for (Entry<Component, String> component : components.entrySet()) {
		if (component == null || component.getKey() == null || component.getValue() == null) {
		    continue;
		}
		Component componentIns = component.getKey();
		String styleName = component.getValue();
		removeStyleUIComponent(componentIns, styleName);
	    }
	}
    }

    public void removeStyleUIComponent(Component component, String styleName) {
	if (component != null && styleName != null) {
	    component.removeStyleName(styleName);
	}
    }

    public void removeErrorStyleAllUIComponents(Component component) {
	if (component != null) {
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_STYLE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    String errorStyle = MAP_ERROR_STYLES.get(component.getClass());
	    if (errorStyle != null) {
		component.removeStyleName(errorStyle);
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			removeErrorStyleAllUIComponents(componentIns);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			removeErrorStyleAllUIComponents(component2);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		removeErrorStyleAllUIComponents(panel.getContent());
	    }
	}
    }

    public void removeErrorStyleUIComponents(List<Component> components) {
	if (components != null) {
	    for (Component component : components) {
		String errorStyle = MAP_ERROR_STYLES.get(component.getClass());
		if (errorStyle != null) {
		    component.removeStyleName(errorStyle);
		}
	    }
	}
    }

    public void removeErrorStyleUIComponent(Component component) {
	if (component != null) {
	    String errorStyle = MAP_ERROR_STYLES.get(component.getClass());
	    component.removeStyleName(errorStyle);
	}
    }

    public void setVisibleUIComponents(List<Component> components, List<Component> excludeComponent, boolean visible) {
	if (components != null) {
	    for (Component component : components) {
		if (component == null) {
		    continue;
		}
		if (excludeComponent != null && !excludeComponent.isEmpty() && excludeComponent.contains(component)) {
		    continue;
		}
		Object obj = component.getId();
		if (obj != null && obj instanceof String) {
		    String dataStr = (String) obj;
		    if (dataStr.indexOf(EXCLUDE_VISIBLE_COMPONENT_PREFIX) > 0) {
			return;
		    }
		}
		setVisibleUIComponent(component, visible);
	    }
	}
    }

    public void setVisibleUIComponent(Component component, boolean visible) {
	if (component != null) {
	    component.setVisible(visible);
	}
    }

    public void setVisibleAllUIComponent(Component component, List<Component> excludeComponent, boolean visible) {
	if (component != null) {
	    if (excludeComponent != null && !excludeComponent.isEmpty() && excludeComponent.contains(component)) {
		return;
	    }
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_VISIBLE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		view.setVisible(true);
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			setVisibleAllUIComponent(componentIns, excludeComponent, visible);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		layout.setVisible(true);
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			setVisibleAllUIComponent(component2, excludeComponent, visible);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		panel.setVisible(true);
		setVisibleAllUIComponent(panel.getContent(), excludeComponent, visible);
	    } else {
		component.setVisible(visible);
	    }
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(INCLUDE_VISIBLE_COMPONENT_PREFIX) > 0) {
		    component.setVisible(visible);
		}
	    }
	}
    }

    public void setVisibleAllUIComponent(Component component, boolean visible) {
	if (component != null) {
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(EXCLUDE_VISIBLE_COMPONENT_PREFIX) > 0) {
		    return;
		}
	    }
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			setVisibleAllUIComponent(componentIns, visible);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			setVisibleAllUIComponent(component2, visible);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		setVisibleAllUIComponent(panel.getContent(), visible);
	    }
	    component.setVisible(visible);
	}
    }

    public void setVisibleAllUIComponentWithIncludePrefix(Component component, boolean visible) {
	if (component != null) {
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			setVisibleAllUIComponentWithIncludePrefix(componentIns, visible);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			setVisibleAllUIComponentWithIncludePrefix(component2, visible);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		setVisibleAllUIComponentWithIncludePrefix(panel.getContent(), visible);
	    }
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(INCLUDE_VISIBLE_COMPONENT_PREFIX) > 0) {
		    component.setVisible(visible);
		}
	    }
	}
    }

    public void clearValueAllUIComponentWithIncludePrefix(Component component) {
	if (component != null) {
	    if (component instanceof AbstractView) {
		AbstractView view = (AbstractView) component;
		if (view != null && view.getComponentCount() > 0) {
		    for (int loop = 0; loop < view.getComponentCount(); loop++) {
			Component componentIns = view.getComponent(loop);
			clearValueAllUIComponentWithIncludePrefix(componentIns);
		    }
		}
	    } else if (component instanceof Layout) {
		Layout layout = (Layout) component;
		if (layout != null && layout.getComponentCount() > 0) {
		    Iterator<Component> componentIns = layout.iterator();
		    while (componentIns.hasNext()) {
			Component component2 = componentIns.next();
			clearValueAllUIComponentWithIncludePrefix(component2);
		    }
		}
	    } else if (component instanceof Panel) {
		Panel panel = (Panel) component;
		clearValueAllUIComponentWithIncludePrefix(panel.getContent());
	    }
	    Object obj = component.getId();
	    if (obj != null && obj instanceof String) {
		String dataStr = (String) obj;
		if (dataStr.indexOf(INCLUDE_VALUE_COMPONENT_PREFIX) > 0) {
		    setValueUIComponent(component, null);
		}
	    }
	}
    }

    public void clearAllUIComponentWithPrefixDefaultValue(Component component, Map<Component, Object> mapDefaultValue) {
	this.clearValueAllUIComponentExcludeLabelWithDefaultValue(component, mapDefaultValue);
	this.clearValueAllUIComponentWithIncludePrefix(component);
	this.setVisibleAllUIComponentWithIncludePrefix(component, false);
	this.removeErrorStyleAllUIComponents(component);
    }

    public void clearAllUIComponentNoInputFieldWithPrefix(Component component) {
	this.clearValueAllUIComponentWithIncludePrefix(component);
	this.setVisibleAllUIComponentWithIncludePrefix(component, false);
	this.removeErrorStyleAllUIComponents(component);
    }

}
